package main

import (
	"fmt"
	"time"
)

func main() {
	regDate, err := time.Parse("2006-01-02", "2021-01-01")
	if err != nil {
		fmt.Println("parse date error.", err)
		return
	}
	date, err := CalculateRegDate(regDate)
	if err != nil {
		fmt.Println("CalculateRegDate error.", err)
		return
	}
	fmt.Println("regDateSum is :", date)
}

func CalculateRegDate(regDate time.Time) (int, error) {
	now := time.Now()
	if regDate.Unix() > now.Unix() {
		return 0, fmt.Errorf("regDate=%v cannot after now", regDate)
		//return 0, errors.New("regDate cannot after now")
	}
	days := int(now.Sub(regDate).Hours() / 24)
	return days, nil
}
